import type { PluginOption } from 'vite';
import vue from '@vitejs/plugin-vue';
import VueJsx from '@vitejs/plugin-vue-jsx';
import ViteYaml from '@modyfi/vite-plugin-yaml';

import { ViteMockServePlugin } from './viteMockServe';
import { SvgIconsPlugin } from './createSvgIconsPlugin';

import { AutoImportPlugin } from './autoImport';
import { ComponentsPlugin } from './component';
import { importFullUiPlugin } from './importFullUi';

type Command = 'build' | 'serve';

export function vitePlugins(command: Command, mode: string) {
	const plugins: PluginOption = [
		vue(),
		VueJsx(),
		ViteYaml(),
		// mock插件
		ViteMockServePlugin(command, mode),
		// svg插件
		SvgIconsPlugin(),
		// 自动导入composition api
		AutoImportPlugin(),
	];

	// mock插件
	// mode === 'mock' && plugins.push(ViteMockServePlugin(command, mode));
	// 打包,用 自动导入组件
	command === 'build' && plugins.push(ComponentsPlugin());
	// 开发模式,用全局导入ui框架，防止卡顿
	command === 'serve' && plugins.push(importFullUiPlugin());

	return plugins;
}
